﻿@using Magicodes.Admin.Web.Areas.Admin.Models.Common
@model OrganizationUnitTreeItemModel
@{
    var organizationUnits = Model.EditModel.AllOrganizationUnits.Where(p => p.ParentId == Model.ParentId || (!p.ParentId.HasValue && !Model.ParentId.HasValue)).ToList();
    if (organizationUnits.Any())
    {
        <ul>
            @foreach (var organizationUnit in organizationUnits)
            {
                var selected = Model.EditModel.MemberedOrganizationUnits.Contains(organizationUnit.Code);
                <li id="@organizationUnit.Id" class="jstree-open" data-jstree='{"selected": @selected.ToString().ToLower()}'>
                    @organizationUnit.DisplayName
                    @Html.Partial("~/Areas/Admin/Views/Common/_OrganizationUnitTreeItem.cshtml", new OrganizationUnitTreeItemModel(Model.EditModel, organizationUnit.Id))
                </li>
            }
        </ul>
    }
}